import store from '../global/Oss'
import { nanoid } from 'nanoid';
import * as format from '../utils/format'

const tool = {
  oss: {
    async upload(file: any, callback: Function) {
      const uuid = nanoid();
      const index = file.name.lastIndexOf('.');
      const suffix = file.name.substring(index + 1);
      const fileName = `hanzi/${format.DateTime(new Date(), 'YYYY-MM-DD')}/${suffix}/${uuid}.${suffix}`
      const res = await store.multipartUpload(fileName, file, {
        parallel: 4,
        partSize: 1024 * 1024,
        progress: function (p: any) {
          // console.log(p);
          // console.log(cpt);
          // console.log(res);
          callback(p)
        }
      });
      console.log('res:', res);
      return res;
    }
  }
}
export default tool